<template>
    <div class="photoAlbumContent">
        <div class="photoAlbumBox">
            <div class="photoAlbumBoxItem" v-for="(item, index) in photoAlbumList" :key="item.id" @click="goPhotoAlbumDetails(item)">
                <div class="photoAlbumBoxItemImg">
                    <SvgIcon width="100px" height="100px" name="work" color="#808080"></SvgIcon>
                </div>
                <div class="photoAlbumBoxItemTitle">
                    <span>{{ item.title }}</span>
                </div>
            </div>
        </div>
        <!-- 姓名验证弹窗 -->
        <van-popup
            v-model:show="showVerifyName"
            round
            position="bottom"
            :style="{ height: '38%' }"
            :close-on-click-overlay=false
            >
            <div class="verifyNameBox">
                <div class="verifyNameBoxTitle">
                <span class="verifyNameBoxTitleText">开始验证本人身份</span>
                </div>
                <div class="verifyNameBoxCenter">
                <div class="verifyNameBoxCenterTop">
                    <span>请填写本人中文姓名首字，以确认身份。</span>
                </div>
                <div class="verifyNameBoxCenterBottom">
                    <div class="verifyNameBoxCenterBottomItem">
                    <div class="verifyNameBoxCenterBottomItemInput">
                        <input type="text" maxlength="1" v-model="firstName" @blur="checkFirstName" name="" id="">
                    </div>
                    </div>
                    <div class="verifyNameBoxCenterBottomItem" v-for="(item, index) in NameList.length-2" :key="index">*</div>
                    <div class="verifyNameBoxCenterBottomItem">{{ NameList[NameList.length-1] }}</div>
                </div>
                </div>
                <div class="verifyNameBoxFoot">
                <div class="verifyNameBoxFootBtn" @click="nameCancel">取消</div>
                <div class="verifyNameBoxFootBtn" style="color: #FF4B38;" @click="nameSumb">确定</div>
                </div>
            </div>
        </van-popup>

    </div>
</template>

<script setup lang="ts">
import { ref, onMounted } from 'vue'
import { useRoute, useRouter } from 'vue-router'
import { showToast, showFailToast } from 'vant'
import friendsStore from '@/store/modules/friendsDataList'
const friendsDataStore = friendsStore()


const route = useRoute()
const router = useRouter()

const firstName = ref<string>('')
const showVerifyName = ref<boolean>(false)
const NameList = ref<any>(['*', '*', '华'])

const checkFirstName = () => {
    // const regex = /^[\u4e00-\u9fa5a-zA-Z\s]+$/; // 匹配汉字英文
    const regex = /[\u4e00-\u9fa5]/; // 匹配汉字
    if (!regex.test(firstName.value)) {
    firstName.value = ''
    showFailToast('请输入正确的姓名');
    return
    }
}

const nameSumb = () => {
    const regex = /^[\u4e00-\u9fa5a-zA-Z\s]+$/;
    if (firstName.value == '' || firstName.value == null) {
        showFailToast('请输入姓名首字');
        return;
    }
    if (!regex.test(firstName.value)) {
        firstName.value = ''
        return;
    }
    if (firstName.value != friendsDataStore.checkPhotoAlbumNameItem.answer) {
        firstName.value = ''
        showFailToast('姓名首字输入有误！');
        return;
    }
    console.log(friendsDataStore.checkPhotoAlbumNameItem)
    router.push({
        path: '/collect/photoAlbumDetails',
        query: {
            // row: { ...friendsDataStore.checkPhotoAlbumNameItem },
        }
    })
}

const nameCancel = () => {
    showVerifyName.value = false;
}

const photoAlbumList = ref<any>([])

const goPhotoAlbumDetails = (item) => {
    NameList.value = item.falseName.split('') || []
    friendsDataStore.handlerSetCheckPhotoAlbumNameItem(item)
    showVerifyName.value = true;
}

onMounted(() => {
    if (friendsDataStore.photoAlbumList && friendsDataStore.photoAlbumList.length) {
        photoAlbumList.value = friendsDataStore.photoAlbumList;
    }
})

</script>


<style lang="scss" scoped>
.photoAlbumContent {
    width: 100%;
    padding: 15px;
    .photoAlbumBox{
        width: 100%;
        display: flex;
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        .photoAlbumBoxItem {
            box-sizing: border-box;
            // width: 50%;
            width: 170px;
            height: 150px;
            margin-bottom: 20px;
            background-color: var(--background);
            display: flex;
            flex-direction: column;
            align-items: center;
            justify-content: center;
            .photoAlbumBoxItemImg {
                margin-bottom: 10px;
            }
            .photoAlbumBoxItemTitle {
                font-size: 12px;
                font-weight: 500;
            }
        }
    }
    .verifyNameBox {
        box-sizing: border-box;
        width: 100vw;
        height: 100%;
        display: flex;
        flex-direction: column;
        overflow: hidden;
        .verifyNameBoxTitle {
            text-align: center;
            height: 60px;
            line-height: 60px;
            // background-color: rgb(249, 249, 249);
            background-color: var(--background);
            .verifyNameBoxTitleText {
            text-align: center;
            span {
                font-size: 16px;
                font-weight: 500;
            }
            }
        }
        .verifyNameBoxCenter {
            width: 100vw;
            box-sizing: border-box;
            padding: 10px 20px;
            flex: 1;
            .verifyNameBoxCenterTop {
                text-align: center;
                height: 40%;
                display: flex;
                justify-content: center;
                align-items: center;
            }
            .verifyNameBoxCenterBottom {
                height: 60%;
                display: flex;
                flex-direction: row;
                align-items: center;
                justify-content: center;
                .verifyNameBoxCenterBottomItem {
                margin: 0 5px;
                font-size: 18px;
                font-weight: 500;
                .verifyNameBoxCenterBottomItemInput {
                    padding: 10px 0px 10px 13px;
                    display: flex;
                    justify-content: center;
                    align-items: center;
                    border: 1px solid #e5e5e5;
                    background-color: var(--background);
                    input {
                        width: 35px;
                        background-color: var(--background);
                        border: none;
                    }
                }
                }
            }
            }
            .verifyNameBoxFoot {
            box-sizing: border-box;
            height: 65px;
            line-height: 65px;
            display: flex;
            flex-direction: row;
            .verifyNameBoxFootBtn {
                width: 50%;
                height: 100%;
                box-sizing: border-box;
                text-align: center;
                border: 1px solid #e5e5e5;
            }
            }
        }
}
</style>